<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class News extends MY_Controller{

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/home
	 *	- or -  
	 * 		http://example.com/index.php/home/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
    function __construct()
    {
        parent::__construct();

		//Google Analytics ID
		$this->data['ga_id'] = 19;	
				
		//Load model
		$this->load->model('news_model');
				
		//Load News Script
		$this->data['js'][] = "newsScript.js";
		//$this->data['css'][]   = (!ONIDEV ? 'defaultStyle2.min.css':'defaultStyle2.css');
		$this->data['css'][] = "newsStyle.css";
		
		 //Load Library
  		$this->load->library('pagination');

		//Router Category
		$this->data['category'] = array(
			'1' => array('path' => 'thai','title' => 'ข่าวบันเทิงไทย'),
			'2' => array('path' => 'inter','title' => 'ข่าวต่างประเทศ'),
			'3' => array('path' => 'asian','title' => 'ข่าวเอเชียน'),
			'4' => array('path' => 'pr','title' => 'ข่าวประชาสัมพันธ์'),
			'5' => array('path' => 'review','title' => 'รีวิวอัลบั้ม'),
			'6' => array('path' => 'movie','title' => 'ข่าววงการหนัง'),
			'7' => array('path' => 'article','title' => 'บทความ'),		
			'15' => array('path' => 'taro','title' => 'เรื่องเผือก ๆ'),		
			'thai' => array('id' => 1,'title' => 'ข่าวบันเทิงไทย'),
			'inter' => array('id' => 2,'title' => 'ข่าวต่างประเทศ'),
			'asian' => array('id' => 3,'title' => 'ข่าวเอเชียน'),
			'pr' => array('id' => 4,'title' => 'ข่าวประชาสัมพันธ์'),
			'review' => array('id' => 5,'title' => 'รีวิวอัลบั้ม'),
			'movie' => array('id' => 6,'title' => 'ข่าววงการหนัง'),
			'article' => array('id' => 7,'title' => 'บทความ'),
			'taro' => array('id' => 15,'title' => 'เรื่องเผือก ๆ')
		);	
		
		//Set SEO Tag
		$this->data['seo_title'] = 'ข่าว ข่าวดารา ข่าวบันเทิง ข่าวหนัง ข่าวซุบซิบ รีวิวเพลง รีวิวอัลบั้ม | You2Play.com';
		$this->data['seo_description'] = 'ข่าวดารา ข่าวบันเทิง ข่าวหนัง ข่าวซุบซิบ รีวิวเพลง รีวิวอัลบั้ม';
		$this->data['seo_keyword'] = 'ข่าวดารา, ข่าวบันเทิง, ข่าวหนัง, รีวิวเพลง, รีวิวอัลบั้ม';				
    }
		
	public function dev($get = NULL)
	{
		//Get PRINT SERVER
		if($get == "get_server"):
			echo "<pre>";
			print_r($_SERVER);
			echo "</pre>";
			exit;	
		endif;
		
		if($get == "get_ip"):
			echo $this->input->ip_address();
			exit;	
		endif;		
		
		if(isset($_POST) && !empty($_POST)):
		$this->load->library('email');
		
		$to = $this->input->post('to');
		$smtp = $this->input->post('smtp');
		$tls = $this->input->post('tls');
		$smtp_host = $this->input->post('smtp_host');
		$smtp_user = $this->input->post('smtp_user');
		$smtp_pass = $this->input->post('smtp_pass');
		$smtp_port = $this->input->post('smtp_port');;
		$name = 'You2Play';
		$subject = 'BACARDI ชวนร่วมฉีกกฎปาร์ตี้แบบเก่าๆ กับ YOU2PLAY PARTY REVOLUCION! 9 ตุลาคมนี้';
		$file = '/home/you2play/engine/static/2013/assets/images/home/you2playparty/newsletter.jpg';
		$message = '<html>
		<body>
		<center>
		<table width="600" border="0" cellspacing="0" cellpadding="0">
		<tr>
		<td>
			<div style="font-size:18px;font-weight:bold;padding:0 0 10px 0;">เตรียมตัวให้พร้อมแล้วมามันส์กันในงาน “BACARDI presents YOU2PLAY PARTY REVOLUCION!" รวมพลเหล่าขบถทางดนตรี ฉีกกฎปาร์ตี้แบบเดิมๆ</div>
		</td>
		</tr>
		<tr>
		<td align="center">
			<div style="font-size:13px;">หากคุณไม่สามารถดูหน้านี้ได้ <a href="http://www.you2play.com/you2playparty"><b>กรุณาคลิก</b></a></div>
		</td>
		</tr>
		<tr>
		<td>
			<a href="http://www.you2play.com/you2playparty"><img src="newsletter.jpg" /></a>
		</td>
		</tr>
		<tr>
		<td>
			<div style="font-size:14px;padding:20px 0 0 0;line-height:25px;"><span style="font-size:18px;font-weight:bold;color:red;">ห้ามพลาด!!</span> ปาร์ตี้สุดมันส์ครั้งแรกในเมืองไทย ของ <b>Porter Robinson</b> ดีเจหนุ่มเลือดใหม่ กับเพลงฮิตสุดมันส์ที่ทำลายสถิติในทุกชาร์ท เสริมทัพด้วย Young Blood ทางดนตรีอย่าง 2 หนุ่ม HipHop <b>“Southside”</b> ที่ครีเอทโชว์ใหม่ที่ยิ่งใหญ่ที่สุดในชีวิตเพื่องานนี้ ร่วมด้วย ดูโอ DJ ดีกรีแชมป์ประเทศไทย <b>“22Bullets”</b> และกองกำลังศิลปินรับเชิญสุดเซอร์ไพรส์อีกเพียบ</div>
			<div style="font-size:14px;padding:15px 0 0 0;line-height:25px;">มาร่วมฉีกกฎปาร์ตี้แบบเก่า แล้วเข้าสู่วิถีการปาร์ตี้ที่แท้จริง วันที่ 9 ตุลาคมนี้ ณ เซ็นเตอร์พ้อยท์ สตูดิโอ (ซอยลาซาล, รถไฟฟ้าสถานีแบริ่ง) ตั้งแต่เวลา 18.00 น. เป็นต้นไป</div>
			<div style="font-size:14px;padding:15px 0 0 0;line-height:25px;">บัตรราคา 800 บาท ซื้อบัตรและอ่านรายละเอียดเพิ่มเติม <a href="http://www.you2play.com/you2playparty"><b>กรุณาคลิก</b></a></div>
		</td>
		</tr>						
		</table>
		</center>
		</body></html>';
		if(!empty($smtp)):
			$config['protocol'] = 'smtp';
		else:
			$config['protocol'] = 'sendmail';
		endif;
		if(!empty($tls)) $config['smtp_crypto'] = "tls";
		$config['smtp_host'] = $smtp_host;
		$config['smtp_user'] = $smtp_user;
		$config['smtp_pass'] = $smtp_pass;
		$config['smtp_port'] = $smtp_port;		
		$config['smtp_port'] = $smtp_port;		
/*		$config['smtp_host'] = 'smtp.gmail.com';
		$config['smtp_user'] = 'onisueka@gmail.com';
		$config['smtp_pass'] = 'TXfd*CVD';
		$config['smtp_port'] = '587';*/
		$config['charset'] = 'utf-8';
		$config['wordwrap'] = TRUE;
		$config['mailtype'] = 'html';
		$config['newline'] = "\r\n";
		$config['crlf']    = "\n"; 

		$this->email->initialize($config);
		$this->email->to($to);
		//$this->email->cc('amornY@pmdplus.com,pulpermP@pmdplus.com');
  		$this->email->from('noreply@you2play.com','Webmaster');
    	$this->email->subject($subject);
		$this->email->attach($file,'inline'); // for the embeded images 
    	$this->email->message($message);
    	$this->email->send();
		?>
		<textarea cols="80" rows="10"><?php echo $this->email->print_debugger();?></textarea>
		<?php
		endif;
		?>
		<!DOCTYPE HTML>
		<html>
			<meta charset="utf-8" />
			<title>Mail Tester</title>
			<body>
				<form method="POST" action="">
				SMTP : <input type="checkbox" name="smtp" id="smtp"/> active<br />
				TLS : <input type="checkbox" name="tls" id="tls"/> active<br />
				SMTP HOST : <input type="text" name="smtp_host" id="smtp_host"/><br />
				SMTP USER : <input type="text" name="smtp_user" id="smtp_user"/><br />
				SMTP PASS : <input type="text" name="smtp_pass" id="smtp_pass"/><br />
				SMTP PORT : <input type="text" name="smtp_port" id="smtp_port"/><br />
				TO(comma to seperate) :  <input type="text" name="to" id="to" value="onisueka@gmail.com"/><br />
				<input type="submit" value="SEND"/>
				</form>
			</body>
		</html>
		<?php
	}

	public function devsolr($type,$id=NULL)
	{		
		switch($type):
			case 'clone':
				if((isset($_GET['only']) && $_GET['only'] == 'song') || !isset($_GET['only'])):
					###########Song###########
					$this->load->library('solr');
					$dataSong = $this->db->select('t.song_id,t.song_name,t.song_tag,j.create_date,j.is_show_ost_song_mood')->
					join('song as j','j.song_id=t.song_id','INNER')->
					order_by('song_id','DESC')->
					get('song_info as t',5000,0)->
					result();
					foreach($dataSong as $key => $value):
						$document[$key] = new Apache_Solr_Document();
						$document[$key]->id = 'song_'.$value->song_id;
						$document[$key]->song_name_s = $value->song_name;
						$document[$key]->song_image_name_s = '';
						$document[$key]->is_ost_song_i = $value->is_show_ost_song_mood;
						$document[$key]->song_tag_s = $value->song_tag;
						$document[$key]->last_modified = date("Y-m-d\TH:i:s\Z",strtotime($value->create_date));	

						$dataArtist = $this->db->select('artist_id')->
						get_where('song_artist',array('song_id' => $value->song_id,'is_default' => '1'))->
						result();
						$artist_id_i_arr = array();
						$artist_name_s = array();
						foreach($dataArtist as $artist):
							$artist_id_i_arr[] = $artist->artist_id;
							$dataArtistName = $this->db->select('artist_name')->get_where('artist_info',array('artist_id' => $artist->artist_id),1)->row();
							$artist_name_s[] = $dataArtistName->artist_name;	
							
						endforeach;
						$document[$key]->artist_id_i_arr = $artist_id_i_arr;
						$document[$key]->song_artist_name_s = implode($artist_name_s,',');

						$dataAlbum = $this->db->select('album_id')->
						get_where('song_album',array('song_id' => $value->song_id,'is_default' => '1'))->
						result();
						$album_id_i_arr = array();
						$album_name_s = array();
						foreach($dataAlbum as $key2 => $album):
							if($key2 == 0):
								$dataSongImage = $this->db->select('j.album_file_name,j.album_file_ext')
								->join('album_info as j','j.album_id=t.album_id','INNER')
								->get_where('song_album as t',array('t.song_id' => $value->song_id,'t.is_default' => '1'),1)->row();
								if(!empty($dataSongImage)) $document[$key]->song_image_name_s = $dataSongImage->album_file_name.'.'.$dataSongImage->album_file_ext;
							endif;
							$album_id_i_arr[] = $album->album_id;
							//Get Album name
							$dataAlbumName = $this->db->select('album_name')->get_where('album_info',array('album_id' => $album->album_id),1)->row();
							$album_name_s[] = $dataAlbumName->album_name;		
						endforeach;	
						$document[$key]->album_id_i_arr = $album_id_i_arr;
						$document[$key]->song_album_name_s = implode($album_name_s,',');
					endforeach;
					if($this->solr->ping() && !empty($document)):
						$this->solr->addDocuments($document);
						$this->solr->commit(); //commit to see the deletes and the document
						$this->solr->optimize(); //merges multiple segments into one
					endif;
				endif;
				
				if((isset($_GET['only']) && $_GET['only'] == 'artist') || !isset($_GET['only'])):
					###########Artist###########		
					$this->load->library('solr');
					$dataArtist = $this->db->select('t.artist_id,t.artist_name,t.artist_short_desc,t.artist_tag,j.create_date')->
					join('artist as j','j.artist_id=t.artist_id','INNER')->
					order_by('artist_id','DESC')->
					get('artist_info as t',1000,0)->
					result();
					foreach($dataArtist as $key => $value):
						$document[$key] = new Apache_Solr_Document();
						$document[$key]->id = 'artist_'.$value->artist_id;
						$document[$key]->artist_name_s = $value->artist_name;	
						$document[$key]->artist_short_desc_s = $value->artist_short_desc;
						$document[$key]->artist_tag_s = $value->artist_tag;
						$document[$key]->last_modified = date("Y-m-d\TH:i:s\Z",strtotime($value->create_date));	
						
						$dataArtistImage = $this->db->order_by('artist_image_order','ASC')->
						get_where('artist_image',array('artist_id' => $value->artist_id),1)->
						row();
						if(!empty($dataArtistImage)):
							$document[$key]->artist_image_name_s = $dataArtistImage->artist_file_name.'.'.$dataArtistImage->artist_file_ext;
						endif;
					endforeach;
					if($this->solr->ping() && !empty($document)):
						$this->solr->addDocuments($document);
						$this->solr->commit(); //commit to see the deletes and the document
						$this->solr->optimize(); //merges multiple segments into one
					endif;
				endif;

				if((isset($_GET['only']) && $_GET['only'] == 'album') || !isset($_GET['only'])):
					###########Album###########		
					$this->load->library('solr');
					$dataArtist = $this->db->select('t.album_id,t.album_name,t.album_file_name,t.album_file_ext,t.album_tag,j.create_date')->
					join('album as j','j.album_id=t.album_id','INNER')->
					order_by('album_id','DESC')->
					get('album_info as t',1000,0)->
					result();
					foreach($dataArtist as $key => $value):
						$document[$key] = new Apache_Solr_Document();
						$document[$key]->id = 'album_'.$value->album_id;
						$document[$key]->album_name_s = $value->album_name;
						$document[$key]->album_tag_s = $value->album_tag;
						$document[$key]->last_modified = date("Y-m-d\TH:i:s\Z",strtotime($value->create_date));	
						if(!empty($value->album_file_name) && !empty($value->album_file_ext)):
							$document[$key]->album_image_name_s = $value->album_file_name.'.'.$value->album_file_ext;
						endif;
					endforeach;
					if($this->solr->ping() && !empty($document)):
						$this->solr->addDocuments($document);
						$this->solr->commit(); //commit to see the deletes and the document
						$this->solr->optimize(); //merges multiple segments into one
					endif;
				endif;
				
				if((isset($_GET['only']) && $_GET['only'] == 'news') || !isset($_GET['only'])):
					###########News###########		
					$this->load->library('solr');
					$dataNews = $this->db->select('t.news_id,t.news_subject,t.news_brief,t.news_tag,j.news_type_id,j.create_date')->
					join('news as j','j.news_id=t.news_id','INNER')->
					order_by('news_id','DESC')->
					get('news_info as t',1000,0)->
					result();

					foreach($dataNews as $key => $value):
						$document[$key] = new Apache_Solr_Document();
						$document[$key]->id = 'news_'.$value->news_id;
						$document[$key]->news_type_id_i = $value->news_type_id;
						$document[$key]->news_name_s = $value->news_subject;	
						$document[$key]->news_short_desc_s = $value->news_brief;
						$document[$key]->news_tag_s = $value->news_tag;
						$document[$key]->last_modified = date("Y-m-d\TH:i:s\Z",strtotime($value->create_date));

						$dataArtist = $this->db->select('artist_id')->
						get_where('news_artist',array('news_id' => $value->news_id))->
						result();
						$artist_id_i_arr = array();
						foreach($dataArtist as $artist):
							$artist_id_i_arr[] = $artist->artist_id;	
						endforeach;
						$document[$key]->artist_id_i_arr = $artist_id_i_arr;
									
						$dataNewsImage = $this->db->order_by('news_image_order','ASC')->
						get_where('news_image',array('news_id' => $value->news_id),1)->
						row();
						if(!empty($dataNewsImage)):
							$document[$key]->news_image_name_s = $dataNewsImage->news_file_name.'.'.$dataNewsImage->news_file_ext;
						endif;
					endforeach;
					if($this->solr->ping() && !empty($document)):
						$this->solr->addDocuments($document);
						$this->solr->commit(); //commit to see the deletes and the document
						$this->solr->optimize(); //merges multiple segments into one
					endif;
				endif;
				
				if((isset($_GET['only']) && $_GET['only'] == 'video') || !isset($_GET['only'])):
					###########Video###########
					$this->load->library('solr');
					$dataVideo = $this->db->select('t.video_id,t.video_name,t.video_thumb_name,t.video_thumb_ext,t.video_tag,j.is_relate_song,j.create_date')->
					join('video as j','j.video_id=t.video_id','INNER')->
					order_by('video_id','DESC')->
					get('video_info as t',5000,0)->
					result();
					foreach($dataVideo as $key => $value):
						$document[$key] = new Apache_Solr_Document();
						$document[$key]->id = 'video_'.$value->video_id;
						$document[$key]->video_name_s = $value->video_name;
						$document[$key]->video_image_name_s = $value->video_thumb_name.'.'.$value->video_thumb_ext;
						$document[$key]->video_tag_s = $value->video_tag;
						$document[$key]->last_modified = date("Y-m-d\TH:i:s\Z",strtotime($value->create_date));	

						if($value->is_relate_song):
							$song_id_i_arr = array();
							$artist_id_i_arr = array();
							$album_id_i_arr = array();		
							$dataVideoSong = $this->db->select('song_id')->
							get_where('video_song',array('video_id' => $value->video_id))->
							result();
							foreach($dataVideoSong as $song):
								$song_id_i_arr[] = $song->song_id;
								$dataSongArtist = $this->db->select('artist_id')->
								get_where('song_artist',array('song_id' => $song->song_id,'is_default' => '1'),1)->
								row();
								$artist_id_i_arr[] = $dataSongArtist->artist_id;
								$dataSongAlbum = $this->db->select('album_id')
								->get_where('song_album',array('song_id' => $song->song_id,'is_default' => '1'),1)
								->row();
								$album_id_i_arr[] = $dataSongAlbum->album_id;			
							endforeach;
							$document[$key]->song_id_i_arr = $song_id_i_arr;
							$document[$key]->artist_id_i_arr = $artist_id_i_arr;
							$document[$key]->album_id_i_arr = $album_id_i_arr;						
						else:
							$dataArtist = $this->db->select('artist_id')->
							get_where('video_artist',array('video_id' => $value->video_id))->
							result();
							$artist_id_i_arr = array();
							foreach($dataArtist as $artist):
								$artist_id_i_arr[] = $artist->artist_id;	
							endforeach;
							$document[$key]->artist_id_i_arr = $artist_id_i_arr;

							$dataAlbum = $this->db->select('album_id')->
							get_where('video_album',array('video_id' => $value->video_id))->
							result();
							$album_id_i_arr = array();
							foreach($dataAlbum as $album):
								$album_id_i_arr[] = $album->album_id;		
							endforeach;	
							$document[$key]->album_id_i_arr = $album_id_i_arr;						
						endif;
					endforeach;
					if($this->solr->ping() && !empty($document)):
						$this->solr->addDocuments($document);
						$this->solr->commit(); //commit to see the deletes and the document
						$this->solr->optimize(); //merges multiple segments into one
					endif;
				endif;
				
				if((isset($_GET['only']) && $_GET['only'] == 'movie') || !isset($_GET['only'])):
					###########Movie###########
					$this->load->library('solr');
					$dataMovie = $this->db->select('t.movie_id,t.movie_name,t.movie_tag,j.create_date')->
					join('movie as j','j.movie_id=t.movie_id','INNER')->
					order_by('movie_id','DESC')->
					get('movie_info as t',1000,0)->
					result();
					//t.movie_thumb_name,t.movie_thumb_ext
					foreach($dataMovie as $key => $value):
						$dataImage = $this->db->select('movie_file_name,movie_file_ext')
						->order_by('movie_image_order','ASC')
						->get_where('movie_image',array('movie_id' => $value->movie_id))
						->row();
						$document[$key] = new Apache_Solr_Document();
						$document[$key]->id = 'movie_'.$value->movie_id;
						$document[$key]->movie_name_s = $value->movie_name;
						if(!empty($dataImage)):
						$document[$key]->movie_image_name_s = $dataImage->movie_file_name.'.'.$dataImage->movie_file_ext;
						endif;
						$document[$key]->movie_tag_s = $value->movie_tag;
						$document[$key]->last_modified = date("Y-m-d\TH:i:s\Z",strtotime($value->create_date));	
					endforeach;
					if($this->solr->ping() && !empty($document)):
						$this->solr->addDocuments($document);
						$this->solr->commit(); //commit to see the deletes and the document
						$this->solr->optimize(); //merges multiple segments into one
					endif;
				endif;
				
				if((isset($_GET['only']) && $_GET['only'] == 'chords') || !isset($_GET['only'])):
					###########Chords###########
					$this->load->library('solr');
					$dataResult = $this->db
					->join('chords_info as j','j.chords_id=t.chords_id','INNER')
					->order_by('t.chords_id','DESC')
					->get('chords as t',1000,0)
					->result();
					
					foreach($dataResult as $key => $value):
						$document[$key] = new Apache_Solr_Document();
						$document[$key]->id = 'chords_'.$value->chords_id;
						$document[$key]->chords_name_s = $value->song_name;
						$document[$key]->chords_image_name_s = '';
						$document[$key]->chords_tag_s = $value->chords_tag;
						if(!empty($value->song_id)):
							$dataSongAlbum = $this->db->select('j.album_file_name,j.album_file_ext')
							->join('album_info as j','j.album_id=t.album_id','INNER')
							->get_where('song_album as t',array('t.song_id' => $value->song_id),1)
							->row();
							$document[$key]->chords_image_name_s = $dataSongAlbum->album_file_name.'.'.$dataSongAlbum->album_file_ext;
							$document[$key]->song_id_i = $value->song_id;
						else:
							if(!empty($value->album_file_name)) $document[$key]->chords_image_name_s = $value->album_file_name.'.'.$value->album_file_ext;
						endif;
						$document[$key]->last_modified = date("Y-m-d\TH:i:s\Z",strtotime($value->create_date));
					endforeach;
					if($this->solr->ping() && !empty($document)):
						$this->solr->addDocuments($document);
						$this->solr->commit(); //commit to see the deletes and the document
						$this->solr->optimize(); //merges multiple segments into one
					endif;
				endif;				
				echo "finish :)";				
			break;
			case 'search':
				$this->load->library('solr');
				$query = $this->input->get('query');
				$dataResult = $this->solr->query($query)->limit(3)->order_by(array('last_modified' => 'desc'))->result();
				echo "มีทั้งหมด ".$this->solr->query($query)->count_all_results()." ระเบียน";
				echo "<pre>";
				print_r($dataResult);
				echo "</pre>";		
			break;
			case 'delete':
				//Update Solr
				$this->load->library('solr');	
				$this->solr->deleteById($id);
				$this->solr->commit(); //commit to see the deletes and the document
				$this->solr->optimize(); //merges multiple segments into one				
			break;
		endswitch;		
	}
	
	public function devclone()
	{
/*#############oni_fashion_image#############*/		
		$SQL = "SELECT t.entry_id,j.image_name as old_name,j.image_key as fashion_file_name,j.ext as fashion_file_ext,j.image_order as fashion_image_order FROM you2play_ee.exp_channel_titles as t INNER JOIN you2play_ee.exp_entry_gallery_files as j ON (j.entry_id=t.entry_id) WHERE t.channel_id = 17 AND t.entry_id >= 29214 ORDER BY t.entry_id ASC";
		$dataResult = $this->db->query($SQL)->result();
		$upload_path = '/home/you2play/engine/static/2013/assets/uploads/';
		foreach($dataResult as $key => $value):	
			$old_path = '/home/you2play/engine/static/files/images/src/'.($value->entry_id % 5000)."/".($value->entry_id % 100)."/";
				//Resize Image
				if(!empty($value->old_name)):
					if(file_exists($old_path.$value->old_name.'.'.$value->fashion_file_ext)):
						$data = imageResize(array(
							'source_image' => $old_path.$value->old_name.'.'.$value->fashion_file_ext,
							'new_path' => $this->upload_folder.'fashion/images/',
							'dimension' => array(					
								array(
									'width' => 120,
									'height' => 120
								)								
							),
							'watermark' => $upload_path.'watermark/watermark.png'
						//),($value->entry_id % 5000).'_'.($value->entry_id % 100).'_'.$value->fashion_file_name);
						),$value->fashion_file_name);
					endif;
				endif;			
		endforeach;	
		echo "fin";
		exit;	
	}	
		
	/*Home*/	 
	public function index($category=NULL)
	{
		if($this->input->post('ajax')) $this->ajax_news_pager('Update',TRUE);

		//Load Javascript
		$this->data['js'][] = "jquery.multipleelements.cycle.min.js";
				
		//Load Module
		$this->data['module'] = $this->module('news');
		
		//Load Top Sub Menu
		$this->data['top_sub_menu'] = $this->load->view($this->router->class."/top_sub_menu",'', TRUE);				
		
		//News Hilight
		if ( !$this->data['dataNewsHilight'] = $this->memcache->get('dataNewsHilight')):
			$this->data['dataNewsHilight'] = $this->db->select('t.news_id,t.views,t.news_publish_date,j.news_subject,j.news_brief')
			->join('news_info as j','j.news_id=t.news_id','INNER')
			->order_by('t.news_publish_date','DESC')
			->get_where('news as t',"t.is_main_hilight = '1' AND t.is_publish = '1' AND t.news_publish_date <= NOW()",4)
			->result();
			foreach($this->data['dataNewsHilight'] as $value):
				$value->image = $this->db->order_by("news_image_order ASC,news_image_id ASC")->get_where('news_image',array('news_id' => $value->news_id),1)->row();
			endforeach;
			//Cache Set
			$this->memcache->set('dataNewsHilight', $this->data['dataNewsHilight'], $this->memcache_time);
		endif;
		
		//News Update
		if(!intval($this->input->get('p'))):
			if ( !$this->data['dataNewsUpdate'] = $this->memcache->get('dataNewsUpdate')):
				$this->data['dataNewsUpdate'] = $this->ajax_news_pager('Update');
				//Cache Set
				$this->memcache->set('dataNewsUpdate', $this->data['dataNewsUpdate'], $this->memcache_time);		
			endif;
		else:
			$this->data['dataNewsUpdate'] = $this->ajax_news_pager('Update');
		endif;
		
		//News Article
		if ( !$this->data['dataNewsArticle'] = $this->memcache->get('dataNewsArticle')):
			$this->data['dataNewsArticle'] = $this->db->select('t.news_id,t.views,t.news_publish_date,j.news_subject,j.news_brief')
			->join('news_info as j','j.news_id=t.news_id','INNER')
			->order_by('t.news_publish_date','DESC')
			->get_where('news as t',"t.news_type_id = 7 AND t.is_publish = '1' AND t.news_publish_date <= NOW()",1)
			->row();
			if(!empty($this->data['dataNewsArticle'])):
				$this->data['dataNewsArticle']->image = $this->db->order_by("news_image_order ASC,news_image_id ASC")->get_where('news_image',array('news_id' => $this->data['dataNewsArticle']->news_id),1)->row();
			endif;
			//Cache Set
			$this->memcache->set('dataNewsArticle', $this->data['dataNewsArticle'], $this->memcache_time);			
		endif;

		//News Album Review
		$this->memcache->delete('dataNewsAlbumReview');
		if ( !$this->data['dataNewsAlbumReview'] = $this->memcache->get('dataNewsAlbumReview')):	
			$this->data['dataNewsAlbumReview'] = $this->db->select('t.news_id,t.views,t.news_publish_date,j.news_subject,j.news_brief')
			->join('news_info as j','j.news_id=t.news_id','INNER')
			->order_by('t.news_publish_date','DESC')
			->get_where('news as t',"t.news_type_id = 5 AND t.is_publish = '1' AND t.news_publish_date <= NOW()",20)
			->result();
			foreach($this->data['dataNewsAlbumReview'] as $value):
				$value->image = $this->db->order_by("news_image_order ASC,news_image_id ASC")->get_where('news_image',array('news_id' => $value->news_id),1)->row();
			endforeach;
			//Cache Set
			$this->memcache->set('dataNewsAlbumReview', $this->data['dataNewsAlbumReview'], $this->memcache_time);			
		endif;
		
		/*News Thai*/
		if ( !$this->data['dataNewsThai'] = $this->memcache->get('dataNewsThai')):
			$this->data['dataNewsThai'] = $this->db->select('t.news_id,t.views,t.news_publish_date,j.news_subject,j.news_brief')
			->join('news_info as j','j.news_id=t.news_id','INNER')
			->order_by('t.news_publish_date','DESC')
			->get_where('news as t',"t.news_type_id = 1 AND t.is_publish = '1' AND t.news_publish_date <= NOW()",1)
			->row();
			if(!empty($this->data['dataNewsThai'])):
				$this->data['dataNewsThai']->image = $this->db->order_by("news_image_order ASC,news_image_id ASC")->get_where('news_image',array('news_id' => $this->data['dataNewsThai']->news_id),1)->row();
			endif;
			//Cache Set
			$this->memcache->set('dataNewsThai', $this->data['dataNewsThai'], $this->memcache_time);			
		endif;	
				
		/*News Inter*/	
		if ( !$this->data['dataNewsInter'] = $this->memcache->get('dataNewsInter')):
			$this->data['dataNewsInter'] = $this->db->select('t.news_id,t.views,t.news_publish_date,j.news_subject,j.news_brief')
			->join('news_info as j','j.news_id=t.news_id','INNER')
			->order_by('t.news_publish_date','DESC')
			->get_where('news as t',"t.news_type_id = 2 AND t.is_publish = '1' AND t.news_publish_date <= NOW()",1)
			->row();
			if(!empty($this->data['dataNewsInter'])):
				$this->data['dataNewsInter']->image = $this->db->order_by("news_image_order ASC,news_image_id ASC")->get_where('news_image',array('news_id' => $this->data['dataNewsInter']->news_id),1)->row();
			endif;
			//Cache Set
			$this->memcache->set('dataNewsInter', $this->data['dataNewsInter'], $this->memcache_time);				
		endif;	
			
		/*News Asian*/
		if ( !$this->data['dataNewsAsian'] = $this->memcache->get('dataNewsAsian')):
			$this->data['dataNewsAsian'] = $this->db->select('t.news_id,t.views,t.news_publish_date,j.news_subject,j.news_brief')
			->join('news_info as j','j.news_id=t.news_id','INNER')
			->order_by('t.news_publish_date','DESC')
			->get_where('news as t',"t.news_type_id = 3 AND t.is_publish = '1' AND t.news_publish_date <= NOW()",1)
			->row();
			if(!empty($this->data['dataNewsAsian'])):
				$this->data['dataNewsAsian']->image = $this->db->order_by("news_image_order ASC,news_image_id ASC")->get_where('news_image',array('news_id' => $this->data['dataNewsAsian']->news_id),1)->row();
			endif;
			//Cache Set
			$this->memcache->set('dataNewsAsian', $this->data['dataNewsAsian'], $this->memcache_time);			
		endif;
				
		/*News Movie*/
		if ( !$this->data['dataNewsMovie'] = $this->memcache->get('dataNewsMovie')):
			$this->data['dataNewsMovie'] = $this->db->select('t.news_id,t.views,t.news_publish_date,j.news_subject,j.news_brief')
			->join('news_info as j','j.news_id=t.news_id','INNER')
			->order_by('t.news_publish_date','DESC')
			->get_where('news as t',"t.news_type_id = 6 AND t.is_publish = '1' AND t.news_publish_date <= NOW()",1)
			->row();
			if(!empty($this->data['dataNewsMovie'])):
				$this->data['dataNewsMovie']->image = $this->db->order_by("news_image_order ASC,news_image_id ASC")->get_where('news_image',array('news_id' => $this->data['dataNewsMovie']->news_id),1)->row();
			endif;
			//Cache Set
			$this->memcache->set('dataNewsMovie', $this->data['dataNewsMovie'], $this->memcache_time);				
		endif;		
			
		$this->data['content'] = $this->router->class."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);
	}
	
	private function ajax_news_pager($mode,$ajax = FALSE)
	{
		switch($mode):
			case 'Update':
				$per_page = 5;
				$dataLastHilight = $this->db->select('news_id')
				->order_by('news_id','DESC')
				->get_where('news',"is_main_hilight = '1' AND is_publish = '1' AND news_publish_date <= NOW()",4)
				->result();
				$and_where_not_in = '';
				foreach($dataLastHilight as $value):
					$and_where_not_in.= $value->news_id.',';
				endforeach;
				if(!empty($and_where_not_in)) $and_where_not_in = " AND t.news_id NOT IN (".rtrim($and_where_not_in,',').")";	
				$searchCondition = "t.is_publish = '1' AND t.news_publish_date <= NOW()".$and_where_not_in;
				$order_by = "t.news_publish_date DESC";
			break;
			case 'Category':
				$per_page = 10;
				$dataLastHilight = $this->db->select('news_id')
				->order_by('news_id','DESC')
				->get_where('news',"news_type_id = ".$this->data['category'][$this->router->method]['id']." AND is_type_hilight = '1' AND is_publish = '1' AND news_publish_date <= NOW()",1)
				->row();
				$and_not_equal = '';
				if(!empty($dataLastHilight)) $and_not_equal = " AND t.news_id != '".$dataLastHilight->news_id."'";
				$searchCondition = "t.news_type_id = ".$this->data['category'][$this->router->method]['id']." AND t.is_publish = '1' AND t.news_publish_date <= NOW()".$and_not_equal;
				$order_by = "t.news_publish_date DESC";				
			break;
		endswitch;
		/*Pager*/		
		$config['base_url'] = current_url().'?'.query_string(array('p'));
		$config['total_rows'] = $this->db->from('news as t')
		->where($searchCondition)
		->count_all_results();
		$config['per_page'] = $per_page;
		$config['num_links'] = 5;
		$config['first_link'] = '&laquo;';
		$config['first_tag_open'] = '<span class="first">';
		$config['first_tag_close'] = '</span>';				
		$config['last_link'] = '&raquo;';
		$config['last_tag_open'] = '<span class="last">';
		$config['last_tag_close'] = '</span>';		
		$config['next_tag_open'] = '<span class="prev">';
		$config['next_tag_close'] = '</span>';	
		$config['prev_tag_open'] = '<span class="next">';
		$config['prev_tag_close'] = '</span>';			
		$config['cur_tag_open'] = '<span class="num_tag current">';
		$config['cur_tag_close'] = '</span>';
		$config['num_tag_open'] = '<span class="num_tag">';
		$config['num_tag_close'] = '</span>';				
		$config['page_query_string'] = TRUE;
		$config['query_string_segment'] = 'p';
		$this->pagination->initialize($config);
		$this->data['pager'] = $this->pagination->create_links();
		$this->data['dataNews'] = $this->db->select('t.news_id,t.news_type_id,t.views,j.news_subject,t.news_publish_date,j.news_brief')
		->join('news_info as j','j.news_id=t.news_id','INNER')	
		->order_by($order_by)	
		->get_where('news as t',$searchCondition,$config['per_page'],intval($this->input->get('p')))
		->result();
		
		foreach($this->data['dataNews'] as $value):
			$value->image = $this->db->order_by("news_image_order ASC,news_image_id ASC")->get_where('news_image',array('news_id' => $value->news_id),1)->row();
			//if news_type_id is review
			if($this->router->method != "index" && $value->news_type_id == $this->data['category'][$this->router->method]['id']):
				$value->artist = $this->db->select('j.artist_id,j.artist_name')
				->join('artist_info as j','j.artist_id=t.artist_id','INNER')
				->get_where('news_artist as t',array('t.news_id' => $value->news_id))->result();
			endif;
		endforeach;
		
		if($ajax):
			echo $this->load->view($this->router->class."/ajax_news_pager", $this->data, TRUE);
			exit;
		else:
			return $this->load->view($this->router->class."/ajax_news_pager", $this->data, TRUE);		
		endif;			
	}
	
	/*Archives*/
	public function archives($id = NULL,$seo_text = NULL)
	{	
		$is_exist = $this->db->from('news')->where(array('news_id' => $id,'is_publish' => '1'))->count_all_results();
		if(empty($is_exist)) $this->page_missing();
	
		//Rediect if no seo text
		if(empty($seo_text)):
			$dataResult = $this->db->get_where('news_info',array('news_id' => $id),1)->row();
			redirect($news_url.'archives/'.intval($id).'-'.seo_url($dataResult->news_subject), 'location', 301);
		endif;		

		//UPDATE Song (View)
		$this->db->set('views', 'views + 1', FALSE);
		$this->db->where(array('news_id' => $id));
		$this->db->update('news');
		
		//Keep Stat View
		$datetime = date('Y-m-d');
		$is_exist = $this->db->from('news_click_stat')->where(array('news_id' => $id,'update_date' => $datetime))->count_all_results();
		if(!empty($is_exist)):
			$this->db->set('news_click_views', 'news_click_views + 1', FALSE);
			$this->db->where(array('news_id' => $id,'update_date' => $datetime));
			$this->db->update('news_click_stat');
		else:
			$data = array(
				'news_id' => $id,
				'news_click_views' => 1,
				'update_date' => $datetime
			);
			$this->db->insert('news_click_stat',$data);
		endif;
		
		//Load Module
		$this->data['module'] = $this->module('news');
		$this->data['module_facebook_plugins_share'] = $this->module_facebook_plugins_share();
		$this->data['module_facebook_plugins_comment'] = $this->module_facebook_plugins_comment($this->data['news_url'].'archives/'.$id);
		
		//Load ColorBox
		$this->data['js'][] = "jquery.colorbox-min.js";	
		$this->data['css'][] = "colorbox.css";		
				
		$this->data['dataResults'] = $this->db->select('t.news_id,t.news_type_id,t.views,t.news_publish_date,j.news_subject,j.news_brief,j.news_detail,j.news_relate,j.news_tag,j.author_by')
		->join('news_info as j','j.news_id=t.news_id','INNER')
		->order_by('t.news_publish_date','DESC')
		->get_where('news as t',"t.news_id = '".$id."' AND t.is_publish = '1'",1)
		->row();
		$this->data['dataResults']->image = $this->db->order_by("news_image_order ASC,news_image_id ASC")->get_where('news_image',array('news_id' => $this->data['dataResults']->news_id),1)->row();
		
		//Set SEO Tag
		$this->data['seo_title'] = $this->data['dataResults']->news_subject.' | ข่าวบันเทิง ข่าวหนัง You2Play.com';
		$this->data['seo_description'] = $this->data['dataResults']->news_brief;
		$this->data['seo_keyword'] = 'ข่าวบันเทิง, ข่าวหนัง'.($this->data['dataResults']->news_tag ? ', '.$this->data['dataResults']->news_tag:'');	
					
		$this->data['fb_title'] = $this->data['seo_title'];
		$this->data['fb_description'] = $this->data['dataResults']->news_brief;
		if(!empty($this->data['dataResults']->image)) $this->data['fb_image'] = image_asset_url('../uploads/news/images/original/'.$this->data['dataResults']->image->news_file_name.'.'.$this->data['dataResults']->image->news_file_ext);
		$this->data['fb_type'] = 'article';
		
		//GA Events
		$this->data['ga_event'] = 'CI-'.$id.'-'.seo_url($this->data['dataResults']->news_subject);			
		
		//Load Top Sub Menu
		$this->data['top_sub_menu'] = $this->load->view($this->router->class."/top_sub_menu",$this->data, TRUE);
		
		$this->data['dataNewsRelateManual'] = $this->news_model->getRelate($this->data['dataResults']->news_relate);
		//$this->data['dataNewsRelateManual'] = "";
		
		//Load Library
		$this->load->library('solr');
		$searchSolrNews = '!id:news_'.$id.' AND id:news_* AND news_tag_s:'.($this->data['dataResults']->news_tag != '' ? $this->solr->escapeSolrValue($this->data['dataResults']->news_tag):'*').'';
		$this->data['dataNewsRelateAuto'] = $this->solr->query($searchSolrNews)->limit(3)->result();

		if(count($this->data['dataNewsRelateAuto']) == 0):
			$searchSolrNews = 'id:news_*';
			$this->data['dataNewsRelateAuto'] = $this->solr->query($searchSolrNews)->limit(3)->order_by(array('last_modified' => 'DESC'))->result();
		endif;
		$this->data['content'] = $this->router->class."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);		
	}
	
	/*Category*/
	public function thai(){$this->category();}
	public function inter(){$this->category();}
	public function asian(){$this->category();}
	public function movie(){$this->category();}
	public function pr(){$this->category();}
	public function review(){$this->category();}
	public function article(){$this->category();}
	public function taro(){$this->category();}
	private function category()
	{
		if($this->input->post('ajax')) $this->ajax_news_pager('Category',TRUE);

		//Load Module
		$this->data['module'] = $this->module('news');
				
		//Load Top Sub Menu
		$this->data['top_sub_menu'] = $this->load->view($this->router->class."/top_sub_menu",$this->data, TRUE);
				
		/*News Type Hilight*/
		$this->data['dataTypeHilight'] = $this->db->select('t.news_id,t.views,t.news_publish_date,j.news_subject,j.news_brief')
		->join('news_info as j','j.news_id=t.news_id','INNER')
		->order_by('t.news_id','DESC')
		->get_where('news as t',"t.news_type_id = ".$this->data['category'][$this->router->method]['id']." AND t.is_type_hilight = '1' AND t.is_publish = '1' AND t.news_publish_date <= NOW()",1)->row();
		if(!empty($this->data['dataTypeHilight'])):
			$this->data['dataTypeHilight']->image = $this->db->order_by("news_image_order ASC,news_image_id ASC")->get_where('news_image',array('news_id' => $this->data['dataTypeHilight']->news_id),1)->row();
		endif;
		//News Category
		$this->data['dataResult'] = $this->ajax_news_pager('Category');
		
		$this->data['content'] = $this->router->class."/category";
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);	
	}
	/*Calendar*/
	public function calendar($module=NULL)
	{
		if($module=="archives"):
			preg_match('/(\d+)\-(.+?)$/i',$this->uri->segment(3),$matches);
			if(!empty($matches)):
				$id = @$matches[1]; //Get Calendar ID		
			else:
				preg_match('/(\d+)(\-|)/',$this->uri->segment(3),$matches);
				$id = @$matches[1]; //Get Calendar ID
				$dataResult = $this->db->get_where('calendar_info',array('calendar_id' => $id),1)->row();
				redirect($news_url.'calendar/archives/'.$id.'-'.seo_url($dataResult->calendar_subject), 'location', 301);			
			endif;
			if(empty($id)) $this->page_missing();
			$this->archives_calendar($id);
		else:
			if($this->input->post('ajax')) $this->ajax_calendar_pager(TRUE);
				
			//Load Module
			$this->data['module'] = $this->module('calendar');
			
			//Load Balloon
			$this->data['js'][] = "jquery.balloon-min.js";
			$this->data['css'][] = "jquery.balloon.css";

			if ( !$this->data['dataCalendar'] = $this->memcache->get('dataCalendar')):
				$this->data['dataCalendar'] = $this->ajax_calendar_pager();
				//Cache Set
				$this->memcache->set('dataCalendar', $this->data['dataCalendar'], $this->memcache_time);					
			endif;
			
			$this->data['content'] = $this->router->class."/calendar";
			$this->load->view("templates/".$this->folder_templates."templates", $this->data);
		endif;
	}
	
	private function archives_calendar($id)
	{
		$is_exist = $this->db->from('calendar')->where(array('calendar_id' => $id))->count_all_results();
		if(empty($is_exist)) $this->page_missing();		

		//UPDATE Song (View)
		$this->db->set('views', 'views + 1', FALSE);
		$this->db->where(array('calendar_id' => $id));
		$this->db->update('calendar');
		
		//Load Module
		$this->data['module'] = $this->module('news');
		$this->data['module_facebook_plugins_share'] = $this->module_facebook_plugins_share();
		$this->data['module_facebook_plugins_comment'] = $this->module_facebook_plugins_comment($this->data['news_url'].'calendar/archives/'.$id);
		
		//Load ColorBox
		$this->data['js'][] = "jquery.colorbox-min.js";	
		$this->data['css'][] = "colorbox.css";
				
		$this->data['dataResults'] = $this->db->select('t.calendar_id,t.views,t.calendar_activity_date_start,t.calendar_activity_date_end,j.calendar_subject,j.calendar_brief,j.calendar_detail,j.calendar_place,j.calendar_link')
		->join('calendar_info as j','j.calendar_id=t.calendar_id','INNER')
		->get_where('calendar as t',"t.calendar_id = '".$id."'",1)
		->row();
		$this->data['dataResults']->image = $this->db->order_by("calendar_image_order ASC,calendar_image_id ASC")->get_where('calendar_image',array('calendar_id' => $this->data['dataResults']->calendar_id),1)->row();
		
		//Set SEO Tag
		$this->data['seo_title'] = $this->data['dataResults']->calendar_subject.' | You2Play.com';
					
		$this->data['fb_title'] = $this->data['seo_title'];
		if(!empty($this->data['dataResults']->image)) $this->data['fb_image'] = image_asset_url('../uploads/calendar/images/original/'.$this->data['dataResults']->image->calendar_file_name.'.'.$this->data['dataResults']->image->calendar_file_ext);
		$this->data['fb_type'] = 'event';	
		
		//GA Events
		$this->data['ga_event'] = 'CI-'.$id.'-'.seo_url($this->data['dataResults']->calendar_subject);			
		
		//Load Top Sub Menu
		$this->data['top_sub_menu'] = $this->load->view($this->router->class."/top_sub_menu",$this->data, TRUE);
		
		$this->data['content'] = $this->router->class."/archives_calendar";
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);			
	}
	
	private function ajax_calendar_pager($ajax = FALSE)
	{
		$day = date('d');
		$month = $this->input->post('month');
		$year = $this->input->post('year');
		if(empty($month)) $month = date('n');
		if(empty($year)) $year = date('Y');
		if(!($month == date('n') && $year == date('Y'))) $day = '';
		$Ym = $year.sprintf('%02d',$month);
		$this->data['dataModuleCalendarElement'] = array(
			'd' => $day,
			'm' => $month,
			'y' => $year,
			'month_start' => date('w',mktime(1,1,1,$month,1,$year)),
			'month_end' => date('d',mktime(1,1,1,$month+1,0,$year)),
		);

		$dataModuleCalendarEvent = $this->db->select('t.calendar_id,t.calendar_activity_date_start,t.calendar_activity_date_end,j.calendar_subject,j.calendar_brief,j.calendar_place')
		->join('calendar_info as j','j.calendar_id=t.calendar_id','INNER')
		//->group_by('DATE(t.calendar_activity_date_start)')
		//->order_by('t.calendar_id','DESC')
		->order_by('t.calendar_activity_date_start','ASC')
		->get_where('calendar as t',"t.is_publish = '1' AND (date_format(t.calendar_activity_date_start,'%Y%m') = '".$Ym."' OR date_format(t.calendar_activity_date_end,'%Y%m') = '".$Ym."')")
		->result();
		$this->data['dataModuleCalendarActivity'] = array();
		foreach($dataModuleCalendarEvent as $value):
			$start = date('Ym',strtotime($value->calendar_activity_date_start));
			$end = date('Ym',strtotime($value->calendar_activity_date_end));
			$start_date = intval(date('d',strtotime($value->calendar_activity_date_start)));
			$end_date = intval(date('d',strtotime($value->calendar_activity_date_end)));
			if($Ym == $start): //check this month
				if($Ym != $end):
					$end_date = $this->data['dataModuleCalendarElement']['month_end'];
				endif;
				for($i=$start_date;$i<=$end_date;$i++):
					$this->data['dataModuleCalendarActivity'][$i][] = array(
						'calendar_id' => $value->calendar_id,
						'calendar_subject' => $value->calendar_subject,
						'calendar_brief' => $value->calendar_brief,
						'calendar_place' => $value->calendar_place,
						'calendar_datetime' => date("d/m/Y H:i:s",strtotime($value->calendar_activity_date_start))." - ".date("d/m/Y H:i:s",strtotime($value->calendar_activity_date_end)),
						'image' => @$this->db->order_by("calendar_image_order ASC,calendar_image_id ASC")->get_where('calendar_image',array('calendar_id' => $value->calendar_id),1)->row()
					);				
				endfor;
			else:
				if($Ym != $start):
					$start_date = 1;
				endif;				
				for($i=$start_date;$i<=$end_date;$i++):
					$this->data['dataModuleCalendarActivity'][$i][] = array(
						'calendar_id' => $value->calendar_id,
						'calendar_subject' => $value->calendar_subject,
						'calendar_brief' => $value->calendar_brief,
						'image' => @$this->db->order_by("news_image_order ASC,news_image_id ASC")->get_where('calendar_image',array('calendar_id' => $value->calendar_id),1)->row()
					);				
				endfor;				
			endif;
		endforeach;

		if($ajax):
			echo $this->load->view("news/ajax_calendar_pager", $this->data, TRUE);
			exit;
		else:
			return $this->load->view("news/ajax_calendar_pager", $this->data, TRUE);		
		endif;		
	}
}


/* End of file video.php */
/* Location: ./application/controllers/video.php */